package org.nowcoder.leetcode.arrays;

/**
 * Title  : 189. Rotate Array
 * Source : https://leetcode.cn/problems/rotate-array/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-07-07
 */

public class LeetCode_189 {
    public static void rotate(int[] nums, int k) {
        int len = nums.length;
        int i = 0, j = len - k;
        //当 k > len 时
        if (j < 0) {
            j = len - (k % len);
        }
        for (; j < len; j++) {
            int tmp = nums[j];
            //元素移动
            for (int n = j; n > i; n--) {
                nums[n] = nums[n - 1];
            }
            nums[i++] = tmp;
        }
    }
}
